Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
I am confused - I receive "getMonth is not a function"

even though i assigned a date to the variable, I receive the error message "getMonth is not a function"

Obviously the interpretor does not accept the type of date.

This is th relevant section of the code:

function init(){
            var m=document.getElementById("m");
            var d = Date();
            refresh(d);
        }


        function refresh(d) {
                var month = d.getMonth();

yes, the function is terminated by a } there are more lines to it, but it stops exactly there.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You forgot to use new keyword with Date :

function init(){
  var m=document.getElementById("m");
  var d = new Date();
  refresh(d);
}


function refresh(d) {
  var month = d.getMonth();
  console.log(month)

}

init()

about 4 years ago · Juan Pablo Isaza Denunciar

0

You seem to want to get the constructor, while you're currently defining the function as d.

Read more about Date here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

So, the code fragment should be:

function init(){
            var m=document.getElementById("m");
            var d = new Date();
            refresh(d);
        }


        function refresh(d) {
                var month = d.getMonth();
about 4 years ago · Juan Pablo Isaza Denunciar

0

Date is a class in javascript, so you need to use the new keyword to create a new instance and call methods like getMonth on it.

function init(){
            var m=document.getElementById("m");
            var d = new Date();
            refresh(d);
        }


        function refresh(d) {
                var month = d.getMonth();
                console.log(month);
        }
        
        init();

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda